var AUTH_SUB_SESSION_TOKEN_URL = "/accounts/AuthSubSessionToken";
var UPGRADE_TOKEN_BUTTON_ID = "upgradeTokenButton"

function upgradeToken() {
  var requester = new Requester();
  var responder = new TokenParsingResponder("token");
  requester.request("GET", AUTH_SUB_SESSION_TOKEN_URL, null, responder, "token");
}

TokenParsingResponder = function(idPrefix) {
  this.idPrefix = idPrefix;
}

TokenParsingResponder.prototype.onresponse = function(xmlHttpRequest) {
  displayResponse(xmlHttpRequest, this.idPrefix);
  parseTokenFromResponse(xmlHttpRequest);
}

function parseTokenFromResponse(xmlHttpRequest) {
  if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
    var multiUseToken = document.getElementById("multiUseToken");
    var token = xmlHttpRequest.responseText.split("=")[1].replace(/\s+$/, "");
    multiUseToken.innerHTML = token;
    setTokenCookie(token);
  }
}
